package com.ruoyi.supervise.service.impl.decisupport;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.supervise.config.CityConfig;
import com.ruoyi.supervise.domain.decisupport.City;
import com.ruoyi.supervise.domain.decisupport.MyBigDataAllProHoursPro;
import com.ruoyi.supervise.mapper.decisupport.MyBigDataAllProHoursProMapper;
import com.ruoyi.supervise.service.decisupport.MyBigDataAllProHoursProService;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;

@Service
@DataSource(value = DataSourceType.SLAVE)
public class MyBigDataAllProHoursProServiceImpl implements MyBigDataAllProHoursProService{

    @Autowired
    private MyBigDataAllProHoursProMapper myBigDataAllProHoursProMapper;
    
    @Autowired
    private CityConfig cityConfig;

	@Override
	public List<MyBigDataAllProHoursPro> selectAllPro(MyBigDataAllProHoursPro bd) {
		// TODO Auto-generated method stub
		return myBigDataAllProHoursProMapper.selectAllPro(bd);
	}

	@Override
	public List<MyBigDataAllProHoursPro> selectAllRE(MyBigDataAllProHoursPro bd) {
		// TODO Auto-generated method stub
		return myBigDataAllProHoursProMapper.selectAllRE(bd);
	}

	@Override
	public List<MyBigDataAllProHoursPro> selectAllRESP(MyBigDataAllProHoursPro bd) {
		// TODO Auto-generated method stub
		return myBigDataAllProHoursProMapper.selectAllRESP(bd);
	}

	@Override
	public List<MyBigDataAllProHoursPro> selectAllREBZ(MyBigDataAllProHoursPro bd) {
		// TODO Auto-generated method stub
		return myBigDataAllProHoursProMapper.selectAllREBZ(bd);
	}
	
	/**
	 * 显示出全部工程项目和房地产工程项目表格数据
	 */
	@Override
	public List<MyBigDataAllProHoursPro> selectAllProAndEB(MyBigDataAllProHoursPro bd) {
		List<MyBigDataAllProHoursPro> allPro=myBigDataAllProHoursProMapper.selectAllPro(bd);
		List<MyBigDataAllProHoursPro> allRE=myBigDataAllProHoursProMapper.selectAllRE(bd);
		List<MyBigDataAllProHoursPro> allREBZ=myBigDataAllProHoursProMapper.selectAllREBZ(bd);
		List<MyBigDataAllProHoursPro> allRESP=myBigDataAllProHoursProMapper.selectAllRESP(bd);
		List<MyBigDataAllProHoursPro> allFJ=new ArrayList<MyBigDataAllProHoursPro>();
		//把在yml中设置的城市,设置到MyBigDataAllProHoursPro实体中
		for(City c:cityConfig.getCityList())
		{
			MyBigDataAllProHoursPro m=new MyBigDataAllProHoursPro();
			m.setProjectCityNum(c.getCityname());
			m.setComparedTotalArea("0");
			m.setTotalAreaRESP("0");
			m.setComparedTotalAreaREBZ("0");
			m.setTotalMoney("0");
			m.setTotalAreaRE("0");
			m.setTotalNum("0");
			m.setComparedTotalNum("0");
			m.setComparedTotalAreaRE("0");
			m.setComparedTotalMoney("0");
			m.setComparedTotalAreaRESP("0");
			m.setTotalAreaREBZ("0");
			m.setTotalArea("0");
			allFJ.add(m);
		}
		//根据市县名字，把市县名字相同的数据，放在同一个实体上
		for(MyBigDataAllProHoursPro fj:allFJ)
		{
			if(allPro!=null) {
				for(MyBigDataAllProHoursPro pro:allPro)
				{
					if(StrUtil.isNotBlank(pro.getProjectCityNum()) && pro.getProjectCityNum().equals(fj.getProjectCityNum()))
					{
						fj.setTotalNum(pro.getTotalNum());
						fj.setComparedTotalNum(pro.getComparedTotalNum());
						fj.setTotalArea(pro.getTotalArea());
						fj.setComparedTotalArea(pro.getComparedTotalArea());
						fj.setTotalMoney(pro.getTotalMoney());
						fj.setComparedTotalMoney(pro.getComparedTotalMoney());
					}
				}
			}
			if(allRE!=null) {
				for(MyBigDataAllProHoursPro re:allRE)
				{
					if(StrUtil.isNotBlank(re.getProjectCityNumRE()) && re.getProjectCityNumRE().equals(fj.getProjectCityNum()))
					{
						fj.setTotalAreaRE(re.getTotalAreaRE());
						fj.setComparedTotalAreaRE(re.getComparedTotalAreaRE());
					}
				}
			}
			if(allREBZ!=null) {
				for(MyBigDataAllProHoursPro rebz:allREBZ)
				{
					if(StrUtil.isNotBlank(rebz.getProjectCityNumREBZ()) && rebz.getProjectCityNumREBZ().equals(fj.getProjectCityNum()))
					{
						fj.setTotalAreaREBZ(rebz.getTotalAreaREBZ());
						fj.setComparedTotalAreaREBZ(rebz.getComparedTotalAreaREBZ());
					}
				}
			}
			if(allRESP!=null) {
				for(MyBigDataAllProHoursPro resp:allRESP)
				{
					if(StrUtil.isNotBlank(resp.getProjectCityNumRESP()) && resp.getProjectCityNumRESP().equals(fj.getProjectCityNum()))
					{
						fj.setTotalAreaRESP(resp.getTotalAreaRESP());
						fj.setComparedTotalAreaRESP(resp.getComparedTotalAreaRESP());
					}
				}
			}
		}
		return allFJ;
	}

	@Override
	public MyBigDataAllProHoursPro selectAllProProvince(MyBigDataAllProHoursPro bd) {
		// TODO Auto-generated method stub
		return myBigDataAllProHoursProMapper.selectAllProProvince(bd);
	}

	@Override
	public MyBigDataAllProHoursPro selectAllREProvince(MyBigDataAllProHoursPro bd) {
		// TODO Auto-generated method stub
		return myBigDataAllProHoursProMapper.selectAllREProvince(bd);
	}

	@Override
	public MyBigDataAllProHoursPro selectAllRESPProvince(MyBigDataAllProHoursPro bd) {
		// TODO Auto-generated method stub
		return myBigDataAllProHoursProMapper.selectAllRESPProvince(bd);
	}

	@Override
	public MyBigDataAllProHoursPro selectAllREBZProvince(MyBigDataAllProHoursPro bd) {
		// TODO Auto-generated method stub
		return myBigDataAllProHoursProMapper.selectAllREBZProvince(bd);
	}

	/**
	 * 查询显示出全省的统计数据
	 */
	@Override
	public MyBigDataAllProHoursPro selectAllProAndEBProvince(MyBigDataAllProHoursPro bd) {
		MyBigDataAllProHoursPro allProProvince=myBigDataAllProHoursProMapper.selectAllProProvince(bd);
		MyBigDataAllProHoursPro allREProvince=myBigDataAllProHoursProMapper.selectAllREProvince(bd);
		MyBigDataAllProHoursPro allREBZProvince=myBigDataAllProHoursProMapper.selectAllREBZProvince(bd);
		MyBigDataAllProHoursPro allRESPProvince=myBigDataAllProHoursProMapper.selectAllRESPProvince(bd);
		allProProvince.setComparedTotalAreaRE(allREProvince.getComparedTotalAreaRE());
		allProProvince.setTotalAreaRE(allREProvince.getTotalAreaRE());
		allProProvince.setComparedTotalAreaREBZ(allREBZProvince.getComparedTotalAreaREBZ());
		allProProvince.setTotalAreaREBZ(allREBZProvince.getTotalAreaREBZ());
		allProProvince.setComparedTotalAreaRESP(allRESPProvince.getComparedTotalAreaRESP());
		allProProvince.setTotalAreaRESP(allRESPProvince.getTotalAreaRESP());
		return allProProvince;
	}

	@Override
	public int countFJAreaInOneW(MyBigDataAllProHoursPro bd) {
		// TODO Auto-generated method stub
		return myBigDataAllProHoursProMapper.countFJAreaInOneW(bd);
	}

	@Override
	public int countFJAreaOneWToTwoW(MyBigDataAllProHoursPro bd) {
		// TODO Auto-generated method stub
		return myBigDataAllProHoursProMapper.countFJAreaOneWToTwoW(bd);
	}

	@Override
	public int countFJAreaTwoWToFiveW(MyBigDataAllProHoursPro bd) {
		// TODO Auto-generated method stub
		return myBigDataAllProHoursProMapper.countFJAreaTwoWToFiveW(bd);
	}

	@Override
	public int countFJAreaFiveWToTenW(MyBigDataAllProHoursPro bd) {
		// TODO Auto-generated method stub
		return myBigDataAllProHoursProMapper.countFJAreaFiveWToTenW(bd);
	}

	@Override
	public int countFJAreaUpTenW(MyBigDataAllProHoursPro bd) {
		// TODO Auto-generated method stub
		return myBigDataAllProHoursProMapper.countFJAreaUpTenW(bd);
	}

	@Override
	public List<MyBigDataAllProHoursPro> selectAllAreaRERLT(MyBigDataAllProHoursPro bd) {
		List<MyBigDataAllProHoursPro> allREArea=myBigDataAllProHoursProMapper.selectAllAreaRERLT(bd);
		List<MyBigDataAllProHoursPro> allREAreaData=new ArrayList<MyBigDataAllProHoursPro>();
		for(City c:cityConfig.getCityList())
		{
			MyBigDataAllProHoursPro m=new MyBigDataAllProHoursPro();
			m.setProjectCityNumRE(c.getCityname());
			m.setTotalAreaRE("0");
			allREAreaData.add(m);
		}
		for(MyBigDataAllProHoursPro aread:allREAreaData)
		{
			for(MyBigDataAllProHoursPro m:allREArea)
			{
				if(aread.getProjectCityNumRE().equals(m.getProjectCityNumRE()))
				{
					aread.setTotalAreaRE(m.getTotalAreaRE());
				}
			}
		}
		return allREAreaData;
	}

	@Override
	public List<MyBigDataAllProHoursPro> selectAllNumRERLT(MyBigDataAllProHoursPro bd) {
		List<MyBigDataAllProHoursPro> allRENum=myBigDataAllProHoursProMapper.selectAllNumRERLT(bd);
		List<MyBigDataAllProHoursPro> allRENumData=new ArrayList<MyBigDataAllProHoursPro>();
		for(City c:cityConfig.getCityList())
		{
			MyBigDataAllProHoursPro m=new MyBigDataAllProHoursPro();
			m.setProjectCityNumRE(c.getCityname());
			m.setTotalNum("0");
			allRENumData.add(m);
		}
		for(MyBigDataAllProHoursPro arend:allRENumData)
		{
			for(MyBigDataAllProHoursPro m:allRENum)
			{
				if(arend.getProjectCityNumRE().equals(m.getProjectCityNumRE()))
				{
					arend.setTotalNum(m.getTotalNum());
				}
			}
		}
		return allRENumData;
	}

	

}
